package Logs;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

import System.Classifier;
import com.cloudgarden.resource.SWTResourceManager;
/*
 * this class is the gui for LogFile class
 */

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
* @author Shinichi
* Spawns a GUI window of log
*/
public class guiLog extends LogFile {

	private Shell sShell = null;
	private Button refresh;
	private List Logger;
	public guiLog(Classifier a){
		super(a);
	}
	/**
	 * This method initializes sShell
	 */
	private void createSShell() {
		sShell = new Shell(Display.getDefault(),0);

		{
			//Register as a resource user - SWTResourceManager will
			//handle the obtaining and disposing of resources
			SWTResourceManager.registerResourceUser(sShell);
		}
		File f = new File("");
		String go=new String(f.getAbsolutePath());
		Image bg=new Image(Display.getDefault(),go+"/1488184-xs.jpg");
		sShell.setText("Changes Log");
		//sShell.setSize(404, 285);
		sShell.setBounds(310, 62, 404, 255);
		sShell.setLayout(null);
		sShell.setBackgroundImage(bg);
		{
			Logger = new List(sShell, SWT.MULTI | SWT.V_SCROLL |SWT.H_SCROLL| SWT.BORDER);
			Logger.setBounds(18, 12, 366, 196);
			//Logger.setBackgroundImage(bg);
		}
		{
			refresh = new Button(sShell, SWT.PUSH | SWT.CENTER);
			refresh.setText("Refresh");
			refresh.setBounds(170, 216, 65, 23);
			refresh.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			refresh.setBackgroundImage(bg);
			refresh.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					try {
						refresh();
					} catch (Exception e) {}
				}
			});
		}
	}
	public void Open(){
		if((sShell==null)||(sShell.isDisposed())){
			createSShell();
			sShell.open();
			try {
				refresh();
			} catch (Exception e) {}
		}
		else{
			sShell.dispose();
		}
	}
	/**
	 * @throws Exception
	 * refreshes the info
	 */
	public void refresh() throws Exception{
		Logger.removeAll();
		BufferedReader br= new BufferedReader( new FileReader(file));
		String line;
		while((line=br.readLine())!=null){
		 Logger.add(line);
		}
		br.close();

	}

}
